<template>
  <div>
    <el-button style="margin-right: 20px; margin-bottom: 20px" @click="goBack"
      >返 回</el-button
    >
    <!--start --111s-->
    <el-form>
      <el-form-item style="background: #e1e1e1">
        <span style="color: #3a3a3a; margin-left: 10px">订单信息</span>
      </el-form-item>
      <el-form-item style="border-bottom: 1px solid #ebeef5" label-width="0px">
        <div v-if="detaildata.purchasetype === 1">
          <span style="color: #3a3a3a; margin-left: 20px">积分支付</span>
        </div>
        <div v-if="detaildata.purchasetype === 0">
          <span style="color: #3a3a3a; margin-left: 20px">余额支付</span>
        </div>
      </el-form-item>
      <el-form-item style="border-bottom: 1px solid #ebeef5" label-width="0px">
        <el-form-item
          label="创建时间："
          style="width: 30%; display: inline-block; margin-left: 20px"
        >
          <span style="color: #3a3a3a" v-if="detaildata.createtime != null">{{
            detaildata.createtime | formatDateStr("yyyy-MM-dd hh:mm:ss")
          }}</span>
        </el-form-item>
        <el-form-item
          label="付款时间："
          style="margin-left: 80px; width: 30%; display: inline-block"
        >
          <i class="el-icon-time" v-if="detaildata.paytime != null"></i>
          <span style="color: #3a3a3a" v-if="detaildata.paytime != null">{{
            detaildata.paytime | formatDateStr("yyyy-MM-dd hh:mm:ss")
          }}</span>
          <span v-else>无</span>
        </el-form-item>
      </el-form-item>

      <el-form-item style="border-bottom: 1px solid #ebeef5" label-width="0px">
        <el-form-item
          label="发货时间："
          style="width: 30%; display: inline-block; margin-left: 20px"
        >
          <div v-if="detaildata.delivergoodstime != null">
            <span style="color: #3a3a3a">{{
              detaildata.delivergoodstime | formatDateStr("yyyy-MM-dd hh:mm:ss")
            }}</span>
          </div>
          <div v-else>
            <span>无</span>
          </div>
        </el-form-item>
        <el-form-item
          label="完成时间："
          style="margin-left: 80px; width: 30%; display: inline-block"
        >
          <div v-if="detaildata.completiontime != null">
            <i
              class="el-icon-time"
              v-if="detaildata.completiontime != null"
            ></i>
            <span
              v-if="detaildata.completiontime != null"
              style="color: #3a3a3a"
              >{{
                detaildata.completiontime | formatDateStr("yyyy-MM-dd hh:mm:ss")
              }}</span
            >
            <span v-else>无</span>
          </div>
          <div v-else>
            <span>无</span>
          </div>
        </el-form-item>
      </el-form-item>

      <el-form-item style="border-bottom: 1px solid #ebeef5" label-width="0px">
        <el-form-item
          label="订单编号："
          style="width: 30%; display: inline-block; margin-left: 20px"
        >
          <span style="color: #3a3a3a"> {{ detaildata.ordernumber }}</span>
        </el-form-item>
        <el-form-item
          label="订单状态："
          style="margin-left: 80px; width: 30%; display: inline-block"
        >
          <div v-if="detaildata.orderstatus === 0">
            <span style="color: #3a3a3a">待付款</span>
          </div>
          <div v-if="detaildata.orderstatus === 1">
            <span style="color: #3a3a3a">待发货</span>
          </div>
          <div v-if="detaildata.orderstatus === 2">
            <span style="color: #3a3a3a"> 待收货</span>
          </div>
          <div v-if="detaildata.orderstatus === 3">
            <span style="color: #3a3a3a">已完成</span>
          </div>
          <div v-if="detaildata.orderstatus === 4">
            <span style="color: #3a3a3a">已关闭</span>
          </div>
          <div v-if="detaildata.orderstatus === 5">
            <span style="color: #3a3a3a">已取消</span>
          </div>
        </el-form-item>
      </el-form-item>
      <el-form-item style="border-bottom: 1px solid #ebeef5" label-width="0px">
        <el-form-item
          label="运费（元）："
          style="width: 30%; display: inline-block; margin-left: 20px"
        >
          <span style="color: #3a3a3a">{{ detaildata.postage }}</span>
        </el-form-item>
        <el-form-item
          v-if="detaildata.orderstatus !== 6"
          label="实付金额（元）："
          style="margin-left: 80px; width: 50%; display: inline-block"
        >
          <div>
            <span style="color: #3a3a3a">{{ detaildata.orderrealprice }}</span>
          </div>
        </el-form-item>
      </el-form-item>
      <el-form-item style="border-bottom: 1px solid #ebeef5" label-width="0px">
        <el-form-item
          label="快递："
          style="width: 30%; display: inline-block; margin-left: 20px"
        >
          <span v-if="detaildata.orderstatus > 1" style="color: #3a3a3a">{{
            detaildata.expressname
          }}</span>
          <span v-else>无</span>
        </el-form-item>
        <el-form-item
          label="物流信息："
          style="margin-left: 80px; width: 50%; display: inline-block"
        >
          <span v-if="detaildata.orderstatus === 0">无</span>
          <span v-else
            ><el-button
              type="primary"
              size="mini"
              @click.native="handleForm(detaildata)"
              >查看</el-button
            ></span
          >
        </el-form-item>
      </el-form-item>
      <el-form-item style="border-bottom: 1px solid #ebeef5" label-width="0px">
        <el-form-item
          label="发货："
          style="width: 50%; display: inline-block; margin-left: 20px"
        >
          <div v-if="detaildata.orderstatus === 0">
            <span style="color: #3a3a3a">待付款</span>
          </div>
          <div v-if="detaildata.orderstatus === 1">
            <el-button
              type="primary"
              size="mini"
              @click.native="showSend(detaildata)"
              >发货</el-button
            >
          </div>
          <div v-if="detaildata.orderstatus === 2">
            <span style="color: #3a3a3a"> 待收货</span>
          </div>
          <div v-if="detaildata.orderstatus === 3">
            <span style="color: #3a3a3a">已完成</span>
          </div>
          <div v-if="detaildata.orderstatus === 4">
            <span style="color: #3a3a3a">已关闭</span>
          </div>
          <div v-if="detaildata.orderstatus === 5">
            <span style="color: #3a3a3a">已取消</span>
          </div>
        </el-form-item>
      </el-form-item>
    </el-form>

    <!--列表start --222s-->
    <el-table
      ref="multipleTable"
      v-loading="loading"
      :data="detaildata.sdlist"
      :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
      border
    >
      <el-table-column
        label="商品ID"
        prop="commodityid"
        width="50"
        align="center"
      />
      <el-table-column
        label="图片"
        prop="commodityicon"
        width="150"
        align="center"
      >
        <template slot-scope="scope">
          <el-popover
            v-if="scope.row.commodityicon"
            placement="right"
            trigger="hover"
          >
            <img
              :src="scope.row.commodityicon"
              style="width: 400px; border-radius: 3px"
            />
            <img
              slot="reference"
              :src="scope.row.commodityicon"
              style="max-height: 80px; max-width: 50px; border-radius: 5px"
            />
          </el-popover>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column
        label="商品名称"
        prop="commodityname"
        width="200"
        align="center"
      />
      <el-table-column
        label="单价（元）"
        prop="price"
        width="200"
        align="center"
      />
      <el-table-column
        label="数量"
        prop="purchasenum"
        width="200"
        align="center"
      />
      <el-table-column label="规格" prop="inventory" width="200" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.inventory }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="快递"
        prop="expressname"
        width="200"
        align="center"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.expressname != null">{{
            scope.row.expressname
          }}</span>
          <span v-else> 无</span>
        </template>
      </el-table-column>
      <el-table-column label="合计（元）" prop="totalprice" align="center" />
    </el-table>
    <!--卖家-->
    <el-form style="margin-top: 15px">
      <el-form-item style="background: #e1e1e1">
        <span style="color: #3a3a3a; margin-left: 10px">买家信息</span>
        <el-button
          size="small"
          style="position: absolute; right: 30px; top: 4px"
          type="primary"
          @click="editPay"
          :disabled="
            detaildata.orderstatus !== 0 && detaildata.orderstatus !== 1
          "
        >
          修改收货信息</el-button
        >
      </el-form-item>
      <el-form-item style="border-bottom: 1px solid #ebeef5" label-width="0px">
        <el-form-item
          label="用户昵称："
          style="width: 30%; display: inline-block; margin-left: 20px"
        >
          <span style="color: #3a3a3a">{{ detaildata.usernick }}</span>
        </el-form-item>
        <el-form-item
          label="取货方式："
          style="margin-left: 80px; width: 30%; display: inline-block"
        >
          <div v-if="detaildata.pickuptype == 0">
            <span style="color: #3a3a3a">商家配送</span>
          </div>
          <div v-if="detaildata.pickuptype == 1">
            <span style="color: #3a3a3a"> 商家配送</span>
          </div>
        </el-form-item>
      </el-form-item>
      <el-form-item style="border-bottom: 1px solid #ebeef5" label-width="0px">
        <el-form-item
          label="收货人："
          style="width: 30%; display: inline-block; margin-left: 20px"
        >
          <span style="color: #3a3a3a">{{ detaildata.useraddressname }}</span>
        </el-form-item>
        <el-form-item
          label="联系方式："
          style="margin-left: 80px; width: 30%; display: inline-block"
        >
          <span style="color: #3a3a3a">{{ detaildata.useraddressphone }}</span>
        </el-form-item>
      </el-form-item>

      <el-form-item>
        <el-form-item
          label="收货地址："
          style="width: 30%; display: inline-block; margin-left: 20px"
        >
          <div v-if="detaildata.province">
            <span style="color: #3a3a3a">{{
              detaildata.province +
              " " +
              detaildata.city +
              " " +
              detaildata.area +
              " " +
              detaildata.useraddress
            }}</span>
          </div>
          <div v-else>
            <span style="color: #3a3a3a">{{ detaildata.useraddress }}</span>
          </div>
        </el-form-item>
      </el-form-item>
      <el-form-item>
        <el-form-item
          label="买家留言："
          style="width: 30%; display: inline-block; margin-left: 20px"
        >
          <span style="color: #3a3a3a">{{ detaildata.buyermessage }}</span>
        </el-form-item>
      </el-form-item>
    </el-form>

    <el-dialog
      title="修改收货信息"
      :visible.sync="editDiglog"
      width="40%"
      :close-on-click-modal="false"
    >
      <template slot="title">
        <div class="avue-crud__dialog__header">
          <span class="el-dialog__title">
            <span
              style="
                display: inline-block;
                background-color: #3478f5;
                width: 3px;
                height: 20px;
                margin-right: 5px;
                float: left;
                margin-top: 2px;
              "
            ></span>
            修改收货信息
          </span>
        </div>
      </template>
      <el-form
        label-width="100px"
        style="margin-left: 50px"
        :model="detaildata1"
        :rules="detailrules"
        ref="detaildata1"
      >
        <el-form-item label="收货人：" prop="useraddressname">
          <el-input v-model="detaildata1.useraddressname"></el-input>
        </el-form-item>
        <el-form-item label="联系方式：" prop="useraddressphone">
          <el-input v-model="detaildata1.useraddressphone"></el-input>
        </el-form-item>
        <el-form-item label="收货地址：" required>
          <el-col :span="6">
            <el-form-item prop="province">
              <el-select
                v-model="detaildata1.province"
                @change="selectProvince(detaildata1.province)"
                placeholder="请选择省"
              >
                <el-option
                  v-for="item in provinces"
                  :key="item.areaid"
                  :label="item.areaname"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="city">
              <el-select
                v-model="detaildata1.city"
                placeholder="请选择市"
                @change="selectCity(detaildata1.city)"
                prop="city"
              >
                <el-option
                  v-for="item in citys"
                  :key="item.areaid"
                  :label="item.areaname"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="area">
              <el-select
                v-model="detaildata1.area"
                placeholder="请选择县"
                @change="selectCounty(detaildata1.area)"
                prop="country"
              >
                <el-option
                  v-for="item in countys"
                  :key="item.areaid"
                  :label="item.areaname"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="详细信息：" prop="useraddress">
          <el-input
            type="textarea"
            placeholder="请输入详细地址"
            v-model="detaildata1.useraddress"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handelup" type="primary">取消</el-button>
        <el-button
          @click="editSubmit('detaildata1')"
          type="primary"
          v-loading="formloading"
          >确定</el-button
        >
      </span>
    </el-dialog>

    <!--评论-->
    <el-dialog
      title="物流信息"
      :visible.sync="dialoglook"
      width="50%"
      :close-on-click-modal="false"
    >
      <el-form label-width="100px" style="margin-left: 50px">
        <!-- <img src="trailUrl" alt="地图展示有问题，请稍后重试"> -->
        <div v-if="logisticsdata.status == 200">
          <div style="margin-bottom: 20px">
            <div>
              <span style="font-size: 16px; font-weight: bold">承运快递:</span>
              <span style="display: inline-block; margin-left: 20px">{{
                logisticsdata.comname
              }}</span>
            </div>
            <div style="margin-top: 10px">
              <span style="font-size: 16px; font-weight: bold">快递单号:</span>
              <span style="display: inline-block; margin-left: 20px">{{
                logisticsdata.nu
              }}</span>
            </div>
          </div>

          <el-table
            ref="multipleTable"
            v-loading="loading"
            :data="logisticsdata.data"
            :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
            :row-class-name="tableRowClassName"
            border
          >
            <el-table-column
              label="状态"
              prop="status"
              width="70"
              align="center"
            >
              <template slot-scope="scope">
                <div slot="reference" class="name-wrapper">
                  <el-tag size="medium">{{ scope.row.status }}</el-tag>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              label="时间"
              prop="time"
              width="200"
              align="center"
            >
              <template slot-scope="scope">
                <i class="el-icon-time"></i>
                <span style="margin-left: 10px">{{ scope.row.time }}</span>
              </template>
            </el-table-column>
            <el-table-column label="物流信息" prop="context"></el-table-column>
          </el-table>
        </div>
        <div v-if="logisticsdata.Success === false">
          <ul>
            <li>
              <span>{{ logisticsdata.Reason }}</span>
            </li>
          </ul>
        </div>
        <div v-if="logisticsdata.status == null">
          <ul>
            <li>
              <span
                style="
                  color: red;
                  font-size: 16px;
                  font-weight: bold;
                  margin-left: 20px;
                "
              >
                1.请核对物流单号</span
              >
            </li>
            <li>
              <span
                style="
                  color: red;
                  font-size: 16px;
                  font-weight: bold;
                  margin-left: 20px;
                "
                >2.{{ logisticsdata.message }}</span
              >
            </li>
          </ul>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialoglook = false">返回</el-button>
      </span>
    </el-dialog>
    <!--快递-->
    <el-dialog
      title="物流信息"
      :visible.sync="dialogSend"
      width="50%"
      :close-on-click-modal="false"
    >
      <el-form label-width="100px" style="margin-left: 50px" size="small">
        <el-form-item
          class="query-form-item"
          label="快递单号"
          :rules="[{ required: true }]"
        >
          <!-- <span slot="label"><span style="color: red" >*</span>{{"快递单号"}}</span> -->
          <el-input
            v-model="expressnumber"
            placeholder="请输入快递单号"
            @keyup.enter.native="searchcompany"
            clearable
          ></el-input>
        </el-form-item>

        <!--查询条件start --111s-->
        <el-form
          :inline="true"
          label-width="100px"
          class="query-form"
          size="small"
          @submit.native.prevent
        >
          <el-form-item class="query-form-item" label="快递公司名称">
            <el-input
              v-model="query.company"
              placeholder="请输入快递公司"
              prefix-icon="el-icon-search"
              @keyup.enter.native="searchcompany"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-refresh"
              @click="oncompanyRest"
            ></el-button>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="searchcompany"
              >查询</el-button
            >
          </el-form-item>
        </el-form>
        <!--查询条件end-->
        <div>
          <!--列表start --222s-->
          <el-table
            ref="multipleTable"
            v-loading="loading"
            :data="expresscompanylist"
            :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
            @selection-change="handleSelectionChange"
            border
          >
            <el-table-column type="selection" width="50" fixed />
            <el-table-column
              label="快递公司编码ID"
              prop="code"
              width="200"
              align="center"
            />
            <el-table-column label="快递公司" prop="company" align="center" />
          </el-table>
          <!--列表end --222e-->

          <!--分页模块start-->
          <el-pagination
            class="pagination-container"
            background
            :page-size="query.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total,sizes,prev, pager, next, jumper"
            :current-page="query.currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :total="totalNumber"
          ></el-pagination>
          <!--分页模块end-->
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="danger" size="small" @click="submityinfo()"
          >提交</el-button
        >
        <el-button @click="back" size="small">返回</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  getCommodityOrderDetail,
  getlogistics,
  getLogisticsCompany,
  updateOrderStatus,
  updateOrderAddress,
} from "../../api/statistics/statistics.js";
import { getAreaList } from "../../api/companyRelation";
import Tinymce from "../../components/Tinymce/index.vue";
/*用作表单的数据初始化*/
const formJson = {
  commodityid: "", //商品id
};
const Json = {
  orderrealprice: "", //商品id
};

export default {
  components: {
    Tinymce,
  },
  data() {
    var checkPhone = (rule, value, callback) => {
      const phoneReg = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
      if (!value) {
        return callback(new Error("电话号码不能为空"));
      }
      setTimeout(() => {
        // Number.isInteger是es6验证数字是否为整数的方法,实际输入的数字总是识别成字符串
        // 所以在前面加了一个+实现隐式转换

        if (!Number.isInteger(+value)) {
          callback(new Error("请输入数字值"));
        } else {
          if (phoneReg.test(value)) {
            callback();
          } else {
            callback(new Error("电话号码格式不正确"));
          }
        }
      }, 100);
    };
    return {
      provinces: [], //省集合
      citys: [], //市集合
      countys: [], //县集合
      editDiglog: false, //控制修改收货信息弹窗
      orderid: "", //订单id
      formData: formJson, //新增或修改的对象
      fjson: Json, //
      formSumbitLoding: false, //提交
      orderrealprice: "", //支付价格
      createTime: [], //选择日期时需要的model
      sendtime: "",
      taketime: "",
      detaildata: {}, //详细
      detaildata1: {
        // useraddressname:"",//收货人姓名
        // useraddressphone:"",//收货人电话
        // useraddress:"",//收货人详细地址
        // province:"",//省
        // city:"",//市
        // area:"",//县area
      }, //修改信息
      formloading: false,
      detailrules: {
        useraddressname: [
          { required: true, message: "请输入收货人", trigger: "blur" },
        ],
        useraddressphone: [
          { required: true, validator: checkPhone, trigger: "blur" },
        ],
        province: [{ required: true, message: "请选择省", trigger: "change" }],
        city: [{ required: true, message: "请选择市", trigger: "change" }],
        area: [{ required: true, message: "请选择县", trigger: "change" }],
        useraddress: [
          { required: true, message: "请填写详细地址", trigger: "blur" },
        ],
      },
      logisticsdata: {}, //快递信息
      dialoglook: false, //物流
      dialogSend: false, //发货
      formVisible: false, //添加编辑显示
      loading: false, //列表加载
      formLoading: false, //表单提交加载

      expresscompanylist: [], //快递公司列表
      secondorderid: "", //二级订单号码
      expressnumber: "", //物流单号
      company: "", //快递公司
      totalNumber: 0, //分页总页数
      query: {
        //查询条件
        company: "",
        currentPage: 1,
        pageSize: 10,
      },
      queryadress:{},//检索地址

      multipleSelection: [], //多选集合
      rules: {
        //表单校验
        orderrealprice: {
          required: true,
          message: "请输入价格",
          trigger: "blur",
        },
      },
    };
  },

  methods: {
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "success-row";
      } else if (rowIndex === 10) {
        return "success-row";
      }
      return "";
    },
    back() {
      this.oncompanyRest();
      this.dialogSend = false;
    },
    goBack() {
      this.$router.push({
        path: "/order/order", //
      });
    },
    oncompanyRest() {
      this.query = {
        company: "",
        currentPage: 1,
        pageSize: 10,
      };
      this.getinfo();
    },

    searchcompany() {
      this.query.currentPage = 1;
      this.getinfo();
    },
    /*列表复选框选择事件*/
    handleSelectionChange(val) {
      this.multipleSelection = val;
      if (val == "") {
        this.cancelToggle = false;
        return;
      }
      this.cancelToggle = true;
    },
    /*提交事件*/
    submityinfo() {
      console.log(JSON.stringify(this.multipleSelection));

      if (this.expressnumber == null || this.expressnumber == "") {
        this.$message({
          message: "请输入快递单号",
          type: "warning",
        });
        return;
      }
      if (this.multipleSelection.length > 1) {
        this.$message({
          message: "只能选择一个快递",
          type: "warning",
        });
        return;
      }
      var expresscode = this.multipleSelection.map((item) => item.code).join(); //获取所有选中行的id组成的字符串，以逗号分隔
      var expressname = this.multipleSelection
        .map((item) => item.company)
        .join(); //获取所有选中行的id组成的字符串，以逗号分隔
      if (expresscode == "") {
        this.$message({
          message: "请先选择",
          type: "warning",
        });
        return;
      }
      this.updateinfo(
        this.orderid,
        this.expressnumber,
        expresscode,
        expressname
      );
    },
    //更新订单状态
    updateinfo(secondorderid, expressnumber, expresscode, expressname) {
      var params = new URLSearchParams();
      params.append("orderid", secondorderid);
      params.append("expressname", expressname);
      params.append("expresscode", expresscode);
      params.append("expressnumber", expressnumber);
      console.info(params);
      updateOrderStatus(params)
        .then((response) => {
          if (response.code) {
            this.$message.error(response.message);
            this.dialogSend = false;
            return;
          }
          this.$message.success("发货成功"); //+response.message
          this.dialogSend = false;
          this.getList();
          setTimeout(() => {
            this.loading = false;
            this.dialogSend = false;
          }, 0.3 * 1000);
        })
        .catch(() => {
          this.dialogSend = false;
          this.totalNumber = 0;
        });
    },

    /*点击页数*/
    handleCurrentChange(val) {
      this.query.currentPage = val;
      this.getinfo();
    },

    /*选择每页条数【10,20,30,40,50】*/
    handleSizeChange(val) {
      this.query.pageSize = val;
      this.getList();
    },

    //查看物流
    handleForm(row) {
      console.log(row);
      // com  快递公司编码 expresscode
      // num  运单号       expressnumber
      // from 发货地址
      // to      收货地址（省、市、区）其他默认 cityName
      if (row.expresscode == undefined || row.expresscode == null) {
        this.$message.warning("没有物流单号");
        return;
      }
      if (row.expressnumber == undefined || row.expressnumber == null) {
        this.$message.warning("没有物流单号");
        return;
      }
      let data = {
        com: row.expresscode,
        num: row.expressnumber,
        to: this.detaildata.city,
      };

      getlogistics(data)
        .then((response) => {
          if (response.code) {
            this.$message.error(response.message);
            return;
          }
          // console.log(response.data)
          let expressname = {};
          expressname.comname = row.expressname;
          this.logisticsdata = Object.assign({}, expressname, response.data);
          console.log(this.logisticsdata);
          this.trailUrl = response.data.trailUrl;
        })
        .catch(() => {});
      this.dialoglook = true;
    },
    //显示发货列表
    showSend(row) {
      this.dialogSend = true;
      this.secondorderid = row.secondorderid;
      this.getinfo();
    },
    getinfo() {
      //alert("发货")
      this.loading = true;

      var params = new URLSearchParams(this.query);
      //params.append("company", this.company);
      getLogisticsCompany(params)
        .then((response) => {
          if (response.code != 0) {
            this.$message.error(response.message);
            this.loading = false;
            return false;
          }
          this.loading = false;
          this.expresscompanylist = response.data.list;
          this.totalNumber = response.data.totalNumber || 0;
          if (response.data.sdlist != null) {
            this.sendtime = response.data.sdlist[0].taketime;
            this.taketime = response.data.sdlist[0].sendtime;
          }
        })
        .catch(() => {
          this.loading = false;
          this.expresscompanylist = [];
        });
    },

    //显示 查看弹框

    detailForm(index, row) {
      if (row !== null) {
        this.detailVisible = true;
        this.formData = Object.assign({}, row);
        this.formName = "detail";
      }
    },

    // 隐藏详情弹框
    hideDetailForm() {
      // 更改值
      this.detailVisible = !this.detailVisible;
      return true;
    },

    /*获取列表事件*/
    getList() {
      this.loading = true;
      var params = new URLSearchParams();
      params.append("orderid", this.orderid);
      getCommodityOrderDetail(params)
        .then((response) => {
          if (response.code != 0) {
            this.$message.error(response.message);
            this.loading = false;
            return false;
          }
          this.detaildata = response.data;
          this.detaildata1 = JSON.parse(JSON.stringify(response.data));
          console.log(this.detaildata1);
          if (response.data != null && response.data.sdlist != null) {
            this.sendtime = response.data.sdlist[0].taketime;
            this.taketime = response.data.sdlist[0].sendtime;
          }
          this.loading = false;
          //console.info(this.detaildata)
        })
        .catch(() => {
          this.loading = false;
          this.list = [];
        });
    },
    //修改收货信息
    editPay() {
      if (this.$refs.detaildata1) {
        this.$refs.detaildata1.clearValidate();
        this.$refs.detaildata1.resetFields();
      }
      this.getList();
      this.editDiglog = true;
      this.getAddressMap();
    },
    //关闭dialog
    handelup() {
      this.$refs.detaildata1.clearValidate();
      this.$refs.detaildata1.resetFields();
      this.editDiglog = false;
    },
    //确定提交收货信息
    editSubmit(detaildata1) {
      this.$refs[detaildata1].validate((valid) => {
        if (valid) {
          this.formloading = true;
          this.queryadress.orderid = this.detaildata1.orderid;
          this.queryadress.useraddress = this.detaildata1.useraddress;
          this.queryadress.useraddressname = this.detaildata1.useraddressname;
          this.queryadress.useraddressphone = this.detaildata1.useraddressphone;
          updateOrderAddress(this.queryadress)
            .then((res) => {
              if (res.code != 0) {
                this.$message.error(res.message);
                this.formloading = false;
                return false;
              }
              this.formloading = false;
              this.editDiglog = false;
              this.$message.success(res.data);
              this.getList();
            })
            .catch((err) => {
              this.$message.error(err);
              this.formloading = false;
              this.editDiglog = false;
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 查询省市县列表
    /*
     * provinceid 上级ID
     * cityRank 查看的城市级别 0 是省级 1 是市级 2 是县级
     */
    //获取全国省市县
    //获取全国省市县
    areaList(provinceid, cityRank) {
      getAreaList({ provinceid: provinceid })
        .then((response) => {
          // console.log(response)
          if (response.code != 0) {
            this.$message.error(response.message);
            return false;
          }
          switch (cityRank) {
            case 0: // 省列表
              this.provinces = response.data || []; // 省级列表赋值
              break;
            case 1: // 市列表
              this.detaildata1.city = null; // 清除已选市
              this.detaildata1.area = null; // 清除已选县
              this.citys = []; // 清空市类别
              this.countys = []; // 清空县列表
              this.citys = response.data || []; // 市级列表赋值
              break;
            case 2: // 县列表
              this.detaildata1.county = null; // 清除已选县
              this.countys = []; // 清空县列表
              this.detaildata1.area =""
              this.countys = response.data || []; // 县级列表赋值
              break;
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
    // 选择省
    selectProvince(item) {
      this.queryadress.provinceid =item.areaid
      this.areaList(item.areaid, 1);
      this.detaildata1.province = this.detaildata1.province.areaname;
    },
    // 选择市
    selectCity(item) {
      this.queryadress.cityid =item.areaid
      this.areaList(item.areaid, 2);
      this.detaildata1.city = this.detaildata1.city.areaname;
    },
    // 选择县
    selectCounty(item) {
      this.queryadress.areaid =item.areaid
      this.detaildata1.area = item.areaname;
    },
    getAddressMap() {
      getAreaList({ provinceid: null })
        .then((res) => {
          if (res.code != 0) {
            this.$message.error(res.message);
            return false;
          }
          this.provinces = res.data || []; // 省级列表赋值
          const province = this.provinces.filter((v) => {
            return v.areaname == this.detaildata1.province;
          });
          getAreaList({ provinceid: province[0].areaid })
            .then((res) => {
              if (res.code != 0) {
                this.$message.error(res.message);
                return false;
              }
              this.citys = res.data || []; // 市级列表赋值
             
              let city = "";
              this.citys.some((v) => {
                if (v.areaname == this.detaildata1.city) {
                  city = v.areaid;
                  return true;
                }
              });
              getAreaList({ provinceid: city })
                .then((res) => {
                  if (res.code != 0) {
                    this.$message.error(res.message);
                    return false;
                  }
                  this.countys = res.data || []; // 县级列表赋值
                })
                .catch((err) => {
                  this.$message.error(err);
                });
            })
            .catch((err) => {
              this.$message.error(err);
            });
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },

    /*刷新*/
    onRest() {
      this.$router.push({
        path: "",
      });
      //刷新事件需要重置查询条件
      this.createTime = [];
      this.query = {
        currentPage: 1,
        pageSize: 10,
      };
      this.getList();
    },
  },

  mounted() {
    this.orderid = this.$route.query.orderid;
    this.areaList();
  },
  created() {
    this.orderid = this.$route.query.orderid;
    this.getList();
    this.areaList(null, 0); // 全国省查询
  },
};
</script>
<style type="text/css">
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>



